
import request from '@/utils/request'
import { json2FormData } from '@/utils'

/**
 * 业务模块列表
 * */
export const getModularList = async(pageCode) => {
  const data = {
    page: 1,
    rows: 100
  }
  const res = await request({
    url: `/api/v1/categoryBusiness/page`,
    method: 'post',
    data: json2FormData(data),
    headers: {
      'Permission-PerCode': pageCode || 'modular',
      'Permission-App': 'content-center'
    }
  })
  return (res && res.data && res.data.records) || []
}

/**
 * 删除
 * @param {String} id
*/
export function deleteModular(id) {
  return request({
    url: `/api/v1/categoryBusiness/${id}`,
    method: 'delete'
  })
}

/**
 * 保存模块
 * @param {Object} data 保存数据
 * @param {string} data.id
 * @param {string} data.classifyCode 业务模块编码
 * @param {string} data.classifyName 业务模块名称
 *
 * */
export function saveModular(data) {
  return request({
    url: '/api/v1/categoryBusiness',
    method: data.id ? 'put' : 'post',
    data
  })
}
